all modules in folder

I want to iterate through all modules in a folder whether open or not.

The following only looks at open modules.

Module m
Folder f = current
for m in f do {
print "Module " (name m) " is open "\n"
}

I suppose I could open all modules first then close when finishes but there must be better way than this?
SystemAdmin - Wed Jun 17 06:22:25 EDT 2009

Re: all modules in folder
IBM_Gust - Wed Jun 17 07:15:03 EDT 2009

Why do you suppose the help file has an entry of:

for item in folder

Re: all modules in folder
Tony_Goodman - Wed Jun 17 09:39:29 EDT 2009

You need to use the item in folder loop. This includes all items in the current folder, including deleted items. It does not recurse into subfolders so you need to program that yourself if required. The following should get you started.

void processModule(string mName)
{
    Module m = null
 
        m = read(mName, false)
 
        if (null m)
        {
                print("ERROR opening module " mName "\n")
                return
        }
 
        print(mName " ok\n")
 
        close(m)
 
        
}
 
void processFolder(Folder f)
{
        Item i
 
        for i in f do
        {
                if (isDeleted(i)) continue
 
                if (type(i) == "Folder")
                {
                        processFolder(folder(fullName(i)))
                }
                else if (type(i) == "Formal")
                {
                        processModule(fullName(i))
                }
        }
}
 
processFolder(current Folder)

Re: all modules in folder
llandale - Wed Jun 17 11:59:30 EDT 2009

Tony_Goodman - Wed Jun 17 09:39:29 EDT 2009

You need to use the item in folder loop. This includes all items in the current folder, including deleted items. It does not recurse into subfolders so you need to program that yourself if required. The following should get you started.

void processModule(string mName)
{
    Module m = null
 
        m = read(mName, false)
 
        if (null m)
        {
                print("ERROR opening module " mName "\n")
                return
        }
 
        print(mName " ok\n")
 
        close(m)
 
        
}
 
void processFolder(Folder f)
{
        Item i
 
        for i in f do
        {
                if (isDeleted(i)) continue
 
                if (type(i) == "Folder")
                {
                        processFolder(folder(fullName(i)))
                }
                else if (type(i) == "Formal")
                {
                        processModule(fullName(i))
                }
        }
}
 
processFolder(current Folder)

But you will want to process them in a reasonable order, usually: alphebetically and modules before folders; instead of 'Item' order which I believe is the order they were created. So the folder loop should first stage the Items in a local Skip list, with integer Sequencer++ as the Key and the Item as the Data. Then look through the Skip twice, first dealing only Items of type 'Formal', and then only of type 'Folder' or 'Project'. Then of course delete the Skip.

  • Louie

Re: all modules in folder
SystemAdmin - Wed Jul 01 07:11:52 EDT 2009

llandale - Wed Jun 17 11:59:30 EDT 2009
But you will want to process them in a reasonable order, usually: alphebetically and modules before folders; instead of 'Item' order which I believe is the order they were created. So the folder loop should first stage the Items in a local Skip list, with integer Sequencer++ as the Key and the Item as the Data. Then look through the Skip twice, first dealing only Items of type 'Formal', and then only of type 'Folder' or 'Project'. Then of course delete the Skip.

  • Louie

Or as I did,
1. count all of the relevant modules = no_modules
2. create string modulesno_modules
3. iterate again and write the full name of the modules into the array
4. run sort modulesno_modules
5. iterate again over the array

If you have a nice structure with folders containing only folders or modules this makes for a nice sorting...

Kristian

Re: all modules in folder
SystemAdmin - Wed Jul 01 07:43:45 EDT 2009

SystemAdmin - Wed Jul 01 07:11:52 EDT 2009
Or as I did,
1. count all of the relevant modules = no_modules
2. create string modulesno_modules
3. iterate again and write the full name of the modules into the array
4. run sort modulesno_modules
5. iterate again over the array

If you have a nice structure with folders containing only folders or modules this makes for a nice sorting...

Kristian

Further note: if you use a Skip list of string type, i.e.

Skip foobar = createString

the items in the skip list are automatically sorted alphabetically

Re: all modules in folder
llandale - Wed Jul 01 09:55:12 EDT 2009

SystemAdmin - Wed Jul 01 07:43:45 EDT 2009
Further note: if you use a Skip list of string type, i.e.

Skip foobar = createString

the items in the skip list are automatically sorted alphabetically

Yes, sorted in KEY order. Try the following:

Item itm
string NameBase
Skip skpAlpha = createString()   // KEY 'string' base name; DATA: 'string' base Name
Skip skpFound = create()         // KEY 'int' order, DATAL 'string' base Name
int  Order = 0
for itm in (current Folder) do
{  put(skpAlpha, name(itm), name(itm))
   put(skpFound, Order++,   name(itm))
}
print "** Alpha Order:\n"
for NameBase in skpAlpha do
{  print "\t" NameBase "\n"
}
print "** Found Order:\n"
for NameBase in skpFound  do
{  print "\t" NameBase "\n"
}
delete(skpAlpha)
delete(skpFound)